package cn.elwy.rcp.ui.table;

import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import cn.elwy.rcp.ui.table.adapter.TreeNodeAdapterFactory;
import cn.elwy.rcp.ui.table.internal.parser.TablePaneParser;
import cn.elwy.rcp.ui.table.model.ColumnInfo;

public class TablePlugin extends AbstractUIPlugin {

  public static final String PLUGIN_ID = "cn.elwy.rcp.ui.table";

  public static TablePlugin plugin;

  private TablePaneParser tablePaneParser;

  public TablePlugin() {
    tablePaneParser = new TablePaneParser();
  }

  @Override
  public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    registerAdapters();
    tablePaneParser.parseTablePanes();
  }

  private void registerAdapters() {
    Platform.getAdapterManager().registerAdapters(new TreeNodeAdapterFactory(), ColumnInfo.class);
  }

  @Override
  public void stop(BundleContext context) throws Exception {
    plugin = null;
    super.stop(context);
  }

  public static TablePlugin getDefault() {
    return plugin;
  }

  // public static TableInfo getTableInfo(String id) {
  // return getDefault().tablePaneParser.getTablePaneInfo(id);
  // }

}